# -*- coding: utf-8 -*-
# @Time         : 2022/3/3 16:35
# @Author       : Jinxing Lin
# @StudentNumber: 20216523
# @Affiliation  : SUN YAT-SEN UNIVERSITY  SCHOOL OF SYSTEMS SCIENCE AND ENGINEERING
# @Mail         ：linjx83@mail2.sysu.edu.cn
# @FileName     : cal.py
# @Software     : PyCharm

'''
    计算不同算法的POD基的的相似度
'''

import numpy as np

def func(a=np.asarray([2,1,3]), b=np.asarray([1,2,1])):
    abs_a = np.sqrt(np.sum(np.power(a, 2)))
    abs_b = np.sqrt(np.sum(np.power(b, 2)))

    res = np.abs(np.dot(a, b) / (abs_a * abs_b))
    return res


if __name__ == "__main__":
    num = 6
    similarity = np.zeros(3)

    for i in range(num):
        y0 = np.loadtxt(r"./basis_data/POD_basis_NOML.csv", delimiter=',')[:, i].reshape((-1,))
        y1 = np.loadtxt(r"./basis_data/POD_basis_GBDT.csv", delimiter=',')[:, i].reshape((-1,))
        y2 = np.loadtxt(r"./basis_data/POD_basis_LGB.csv", delimiter=',')[:, i].reshape((-1,))
        y3 = np.loadtxt(r"./basis_data/POD_basis_XGB.csv", delimiter=',')[:, i].reshape((-1,))

        similarity[0] += func(y0, y1)
        similarity[1] += func(y0, y2)
        similarity[2] += func(y0, y3)
        print('{:6f}'.format(func(y0, y2)),
              '{:6f}'.format(func(y0, y3)),
              '{:6f}'.format(func(y0, y1)))

    res = similarity / num
    print(res)
